package com.ljx.recruitment.user.controller;

import com.ljx.recruitment.common.domain.vo.resp.ApiResult;
import com.ljx.recruitment.common.domain.vo.resp.PageResp;
import com.ljx.recruitment.security.annotation.ApiPermission;
import com.ljx.recruitment.security.common.PermissionConstant;
import com.ljx.recruitment.security.util.UserUtil;
import com.ljx.recruitment.user.domain.entity.Tenant;
import com.ljx.recruitment.user.domain.vo.req.TenantPageReq;
import com.ljx.recruitment.user.domain.vo.req.TenantSubmitReq;
import com.ljx.recruitment.user.domain.vo.resp.NavItemResp;
import com.ljx.recruitment.user.domain.vo.resp.TenantResp;
import com.ljx.recruitment.user.domain.vo.resp.TenantSearchFilterResp;
import com.ljx.recruitment.user.domain.vo.resp.ThemeConfigResp;
import com.ljx.recruitment.user.service.TenantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-10-31  13:37
 */
@Api(tags = "租户接口")
@RestController
@RequestMapping("/tenant")
public class TenantController {

    @Autowired
    private TenantService tenantService;

    @ApiOperation("根据租户code获取租户信息")
    @GetMapping("/code/{code}")
    public ApiResult<TenantResp> getInfoByCode(@PathVariable("code") String code){
        return ApiResult.success(tenantService.getInfoByCode(code));
    }

    @ApiPermission(permissions = {PermissionConstant.ADMIN_TENANT_SUBMIT})
    @ApiOperation("创建/修改租户")
    @PostMapping("/submit")
    public ApiResult<TenantResp> submit(@Validated @RequestBody TenantSubmitReq req){
        return ApiResult.success(tenantService.submit(req));
    }

    @ApiPermission(permissions = {PermissionConstant.ADMIN_TENANT_QUERY})
    @ApiOperation("获取租户分页")
    @GetMapping("/page")
    public ApiResult<PageResp<Tenant>> getPage(TenantPageReq req){
        return ApiResult.success(tenantService.getPage(req));
    }

    @ApiPermission(permissions = {PermissionConstant.TENANT_SUBMIT})
    @ApiOperation("刷新租户简历配置")
    @PostMapping("/resume/refresh")
    public ApiResult<TenantResp> refreshResume(){
        Long tenantId = UserUtil.tryToGetTenantId();
        return ApiResult.success(tenantService.refreshResume(tenantId));
    }

    @ApiOperation("根据租户搜索过滤条件")
    @GetMapping("/search/filter")
    public ApiResult<List<TenantSearchFilterResp>> getSearchFilter(){
        Long tenantId = UserUtil.tryToGetTenantId();
        return ApiResult.success(tenantService.getSearchFilter(tenantId));
    }

    @ApiPermission(permissions = {PermissionConstant.TENANT_QUERY})
    @ApiOperation("获取主题配置列表")
    @GetMapping("/theme/config/list")
    public ApiResult<List<ThemeConfigResp>> getThemeConfigList(){
        return ApiResult.success(tenantService.getThemeConfigList());
    }

    @ApiOperation("获取导航栏列表")
    @GetMapping("/site/nav/list")
    public ApiResult<List<NavItemResp>> getSiteNavList(){
        return ApiResult.success(tenantService.getSiteNavList());
    }
}
